<?php
class HandbookVo extends SzAbstractMySqlVo
{

    private $userId;
    private $collectionId;
    private $progress;
    private $step;

    /**
     * Initialize HandbookVo.
     *
     * @param $userId
     * @param $collectionId
     * @param $progress
     * @param $step
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return HandbookVo
     */
    public function __construct($userId, $collectionId, $progress, $step, $isInsert = false) {
        $this->userId = $userId;
        $this->collectionId = $collectionId;
        $this->progress = json_decode($progress, true);
        $this->step = $step;

        $this->isInsert = $isInsert;
        $this->voClassName = 'HandbookVo';
        $this->ormName = 'Handbook';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'collectionId' => $this->getCollectionId(),
            'progress' => ($needEncode) ? $this->getProgress() : $this->getRawProgress(),
            'step' => $this->getStep(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'collectionId' => $this->getCollectionId(),
            'progress' => ($needEncode) ? $this->getProgress() : $this->getRawProgress(),
            'step' => $this->getStep(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getCollectionId(),
            $this->getProgress(),
            $this->getStep(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getCollectionId()
    {
        return $this->collectionId;
    }

    public function setCollectionId($val)
    {
        $this->saveColumnStatus(1, $this->collectionId);
        $this->collectionId = $val;
    }

    public function getProgress()
    {
        return json_encode($this->progress);
    }

    public function getRawProgress()
    {
        return $this->progress;
    }

    public function setProgress($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[HandbookVo] The length of column progress exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('HandbookVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[HandbookVo] The length of column progress exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(2, $this->progress);
        $this->progress = $val;
    }

    public function getStep()
    {
        return $this->step;
    }

    public function setStep($val)
    {
        $this->saveColumnStatus(3, $this->step);
        $this->step = $val;
    }

}